package edu.hcnu.service.impl;

import edu.hcnu.mapper.SheBeiMapper;
import edu.hcnu.po.SheBei;
import edu.hcnu.service.SheBeiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SheBeiServiceImpl implements SheBeiService {

    @Autowired
    private SheBeiMapper mapper;


    @Override
    @Cacheable(cacheNames = "all")
    public List<SheBei> list() {
        return mapper.list();
    }

    @Override
    @Cacheable(cacheNames = "queryByID")
    public SheBei queryByID(String id) {
        return mapper.queryByID(id);
    }

    @Override
    @Caching(
            evict = {
                    @CacheEvict(cacheNames = "all"),
                    @CacheEvict(cacheNames = "queryByID")
            }
    )
    public boolean deleteByID(String id) {
        return mapper.delete(id);
    }

    @Override
    @Caching(
            put = {
                    @CachePut("insertSheBei")
            },
            evict = {
            @CacheEvict(cacheNames = "all"),
            @CacheEvict(cacheNames = "queryByID")
    }
    )
    public boolean insertSheBei(SheBei sheBei) {
        return mapper.insert(sheBei);
    }

    @Override
    @Caching(
            put = {
                    @CachePut("updateSheBei")
            },
            evict = {
                    @CacheEvict(cacheNames = "all"),
                    @CacheEvict(cacheNames = "queryByID")
            }
    )
    public boolean updateSheBei(SheBei sheBei) {
        return mapper.update(sheBei);
    }
}
